package com.esm.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.esm.utils.PrintWriterUtil;

import net.sf.json.JSONArray;

/**
 * GetCurrentTimeController
 * 获取当前系统时间控制者
 * @author 魏长均
 *
 */
public class GetCurrentTimeController_wcj extends HttpServlet
{
	private static final long serialVersionUID = 1L;
	private static String patnYear="yyyy";
	private static String patnMonth="MM";
	private static String patnDay="DD";
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
	{
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
	{
		Calendar cal = Calendar.getInstance();
		Date curTime = cal.getTime();
		SimpleDateFormat sdfYear = new SimpleDateFormat(patnYear);
		SimpleDateFormat sdfMonth = new SimpleDateFormat(patnMonth);
		SimpleDateFormat sdfDay = new SimpleDateFormat(patnDay);
		int dateYear= Integer.parseInt(sdfYear.format(curTime)); 
		int dateMonth= Integer.parseInt(sdfMonth.format(curTime)); 
		int dateDay= Integer.parseInt(sdfDay.format(curTime)); 

		JSONArray jao = new JSONArray();
		PrintWriter pw = resp.getWriter();
		jao.add(dateYear);
		jao.add(dateMonth);
		jao.add(dateDay);
		PrintWriterUtil.flushJaoAndClosePrintWriter(pw, jao);
	}
}
